//
//  DoubleExt.swift
//  JiaoZiTaxi
//
//  Created by Hu Gang on 2022/10/12.
//

import Foundation

extension Double {
  var date: Date {
    Date(timeIntervalSince1970: self)
  }

  /// Rounds the double to decimal places value
  func rounded(_ places:Int) -> Double {
    let divisor = pow(10.0, Double(places))
    return (self * divisor).rounded() / divisor
  }

  public static func randomDoubleNumber(lower: Double = 0,upper: Double = 10) -> Double {
    return ((Double(arc4random())/Double(UInt32.max))*(upper - lower) + lower ) / (10000.0)
  }

  public static func randomDistance() -> Double {
    return Double.randomDoubleNumber(lower: 0,upper: 100)
  }
}

